import 'dart:convert';

import 'package:dio/src/response.dart';

/// data : {"uid":"5b304ca93fc6f","nickName":"大松啊","pic":"https://c360-o2o.c360dn.com/moren.jpg","num":"0","isVIP":true,"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJLQU5OWS1BUEkiLCJhdWQiOiJBUFAiLCJpYXQiOjE3MDE0MjY1ODEsIm5iZiI6MTcwMTQyNjU4MSwiZXhwIjoxNzAxNDQ4MTgxLCJqdGkiOiI1MTYyMyIsImlkIjoiNWIzMDRjYTkzZmM2ZiIsInVpZCI6IjViMzA0Y2E5M2ZjNmYifQ.QsQyOUgu8ezUQTdJ65DCfYFtG5OH5GSIvf_Txrv6BK6EwqXQBPT3CSvFNhZVLhgTYja3yBlpTAG79a9uuLqDREQK1aamy6DqrW1YGvuvLIvuJBYGUpdbbZn4qiVmccJ_i1YfXu_QoCKFcsfycvaILcVtlzCZFGj7bkKd0EfDlgw"}
/// status : 200
/// message : "SUCCESS"
/// serverTime : 1701426581.2733481
/// logId : "6569b595c37b5400872ea0c8"
/// msgId : "bc503702-a8ef-45b5-9d12-07ea065606db"

CMBaseResponse cmBaseResponseFromJson(String str) => CMBaseResponse.fromJson(json.decode(str));

String cmBaseResponseToJson(CMBaseResponse data) => json.encode(data.toJson());

class CMBaseResponse<T> {
  int? _status;
  String? _message;
  num? _serverTime;
  String? _logId;
  String? _msgId;

  T? data;

  CMBaseResponse({
    int? status,
    String? message,
    num? serverTime,
    String? logId,
    String? msgId,
  }) {
    _status = status;
    _message = message;
    _serverTime = serverTime;
    _logId = logId;
    _msgId = msgId;
  }

  CMBaseResponse.fromJson(dynamic json) {
    _status = json['status'];
    _message = json['message'];
    _serverTime = json['serverTime'];
    _logId = json['logId'];
    _msgId = json['msgId'];
  }

  CMBaseResponse.netError(Response<dynamic> resp) {
    _status = resp.statusCode;
    _message = resp.statusMessage;
  }

  CMBaseResponse copyWith({
    int? status,
    String? message,
    int? serverTime,
    String? logId,
    String? msgId,
  }) =>
      CMBaseResponse(
        status: status ?? _status,
        message: message ?? _message,
        serverTime: serverTime ?? _serverTime,
        logId: logId ?? _logId,
        msgId: msgId ?? _msgId,
      );

  num? get status => _status;

  String? get message => _message;

  num? get serverTime => _serverTime;

  String? get logId => _logId;

  String? get msgId => _msgId;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['status'] = _status;
    map['message'] = _message;
    map['serverTime'] = _serverTime;
    map['logId'] = _logId;
    map['msgId'] = _msgId;
    return map;
  }

  @override
  String toString() {
    return 'CMBaseResponse{_status: $_status, _message: $_message, _serverTime: $_serverTime, _logId: $_logId, _msgId: $_msgId, data: $data}';
  }
}
